﻿using AttendanceAccounting.Classes;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using TeacherLoad.Classes;

namespace AttendanceAccounting.Windows
{
    /// <summary>
    /// Логика взаимодействия для Attendance.xaml
    /// </summary>
    public partial class Attendance : Window
    {
        //private static int _id = 0;
        //private static Skip _skip;
        public Attendance()
        {
            InitializeComponent();
            listSkip.DataContext = Load();
            
        }

        private List<Student> LoadData()
        {
            DataTable dataTable = SendToServer.GetStudents();
            List<Student> students = new List<Student>();
            if (dataTable.Rows.Count > 0)
            {
                foreach (DataRow row in dataTable.Rows)
                {
                    Student st = new Student(
                        Convert.ToInt32(row[0]),
                        row[1].ToString(),
                        row[2].ToString(),
                        row[3].ToString());
                    students.Add(st);
                }
            }
            return students;
        }

        private List<Skip> LoadDataSkip()
        {
            DataTable dataTable = SendToServer.GetAttendance();
            List<Skip> skip = new List<Skip>();
            if (dataTable.Rows.Count > 0)
            {
                foreach (DataRow row in dataTable.Rows)
                {
                    Skip sk = new Skip(
                        Convert.ToInt32(row[0]),
                        Convert.ToInt32(row[1]),
                        Convert.ToDateTime(row[2]),
                        Convert.ToInt32(row[3]));
                    skip.Add(sk);
                }
            }
            return skip;
        }

        

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //Load();
        }

        private List<Student> Load()
        {
            List<Student> students = LoadData();
            foreach (Student item in students)
            {
                if (item.Id % 2 == 0)
                {
                    item.Net = true;
                }
                else
                {
                    item.Bolezn = true;
                }
            }
            return students;
        }
    }
}
